CC=g++

AR=ar
ARFLAGS=-cvq

JOYSTICK_ROOT=../../joystick_lib
JOYSTICK_LIB=$(JOYSTICK_ROOT)/lib
JOYSTICK_INC=$(JOYSTICK_ROOT)/include

INCS=-I$(JOYSTICK_INC)
LIBS=-L$(JOYSTICK_LIB)

CFLAGS=-c -Wall $(INCS)
LDFLAGS=$(INCS) $(LIBS) -ljoystick -lpthread
SOURCES=test.cpp
OBJECTS=$(SOURCES:.cpp=.o)
LIB_SOURCES=joystick.cpp
LIB_OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=test

all: $(JOYSTICK_LIB) $(SOURCES) $(EXECUTABLE)

$(JOYSTICK_LIB): $(JOYSTICK_ROOT)/$(LIB_SOURCES)
	make -C $(JOYSTICK_ROOT) lib

$(EXECUTABLE): $(OBJECTS) $(JOYSTICK_LIB)
	mkdir -p bin
	$(CC) -o bin/$@ $(OBJECTS) $(LDFLAGS)

%.o: %.cpp
	$(CC) $(CFLAGS) $< -o $@

clean:
	rm -rf *~ bin $(OBJECTS)
	make -C $(JOYSTICK_ROOT) clean

run:
	./bin/$(EXECUTABLE)
